package logic

import (
	"context"
	"stores/mysql"

	"stores/storesrpc/internal/svc"
	"stores/storesrpc/storesrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStoreAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreAddLogic {
	return &StoreAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StoreAddLogic) StoreAdd(in *storesrpc.StoreAddRequest) (*storesrpc.StoreAddResponse, error) {
	// todo: add your logic here and delete this line
	store := mysql.Store{

		Name:    in.Name,
		Address: in.Address,
		Num:     in.Num,
	}
	mysql.DB.Debug().Create(&store)
	return &storesrpc.StoreAddResponse{
		StoreId: int64(store.ID),
	}, nil
}
